<template>
	<view class="allyhq">
		<view class="yhq-one" v-for="(item,index) in yhqList" :key="index" @click="yhqClick(item)">
			<view class="title">
				{{item.title}}
			</view>
			<view class="content">
				备注：{{item.content}}
			</view>
			<view class="money">
				￥{{item.Money}}
			</view>
			<u-button type="error" text="立即领取"></u-button>
		</view>
	</view>
</template>

<script>
	import http from "../../static/http.js"
	export default {
		name: "",
		data() {
			return {
				yhqList: []
			}
		},
		created() {
			this.getAllCou()
		},
		methods: {
			getAllCou() {
				http.httpRequest("/api/user/getAllCoupon", "", "GET").then(res => {
					if(res.data.length == 0){
						uni.showToast({
							title:"暂无数据！",
							icon:"none"
						})
					}
					this.yhqList = res.data
				})
			},
			yhqClick(item) {
				if (item.allCount >= 0) {
					let data = {
						couponId: item.id,
						allCount: item.allCount
					}
					http.httpRequest("/userCoupon/add", data, "POST").then(res => {
						console.log(res);
						uni.showToast({
							title: "领取成功！",
							icon: "none"
						})
					})
				} else {
					uni.showToast({
						title: "已经被领取完啦"
					})
				}
			}
		}
	}
</script>

<style lang="less">
	.allyhq {
		width: 100%;

		.yhq-one {
			width: 95%;
			min-height: 100rpx;
			margin: 10rpx auto;
			background-color: #409EFF;
			border-radius: 10rpx;
			-webkit-mask: radial-gradient(circle at 20px, #0000 20px, red 0) -20px;

			.title {
				padding: 10rpx;
				font-size: 40rpx;
			}

			.content {
				padding: 10rpx;
				font-size: 30rpx;
				color: #fff;
			}

			.money {
				padding: 10rpx;
				color: #dd6161;
				font-size: 50rpx;
				margin-right: 25rpx;
				text-align: right;
			}
		}
	}
</style>
